#include <QCoreApplication>
#include <iostream>
using namespace  std;

//全局变量
int g_a = 10;
int g_b = 10;

//全局常量
const int c_g_a = 10;
const int c_g_b = 10;
int* p ;

typedef struct  xxxxx
{
    int deptno;
    string danme;
}Dept;


void fun4(const int & a ,const int  arr[] ){
    // a=2;
    cout << arr[0] <<endl;
    //arr[0] =100;
    cout << arr[0] <<endl;
    cout << "funcA:" << a <<endl;
}
int main(int argc, char *argv[])
{
    int a =1;
    int  arr[] = {99};
    fun4(a,arr);
    cout << "Arr:" <<arr[0] <<endl;
    cout << "funcA:" << a <<endl;
    return 0;
}




void  funn3(int &x, int &y){
    cout << "funcA:" << x <<endl;

    int temp =x;
    x=y;
    y =temp;

}
void showDept(Dept &d){
    cout << d.deptno << d.danme <<endl;
   ///  d ={30,"bbbb"}; 别名不能指向新对象
    d.deptno =20;
    cout << d.deptno << d.danme <<endl;
}

int main5(int argc, char *argv[])
{
    Dept d1= {10,"AAAAA"};
    showDept(d1);
    cout << d1.deptno << d1.danme <<endl;
    // int a =1;
    // int b =2;
    // funn3(a,b);
    // cout << "mainA:" << a;
    return 0;
}



int main4(int argc, char *argv[])
{
    int a =10; // 信达雅
    int b =20;
    int &age = a; // 为a变量取了别名为age

    cout << "age: " << age <<endl;
    age ++;
    cout << "age: " << age <<endl;

    a =12;
    cout << "age: " << age <<endl;

    // int &age = b;  相当于对两个不同的变量定义了相同的别名
    return 0;
}




int main3(int argc, char *argv[])
{
    int arr_len = 10;
    int* arr = new int[arr_len];
    // int LEN =  sizeof(arr) /sizeof(arr[0]);
    for(int index = 0 ;  index <arr_len;index++ ){
        arr[index] = index +index;
    }
    for (int index = 0; index < 10; index++)
    {
        cout << arr[index] << endl;
    }

    return 0;
}





int* func(){
    // int a =99;
    int *p =  new int(10); // new 返回指针
    cout << "AAddr:" << p << endl;
    cout << "PV:" << *p << endl;
    // delete p; // 野指针
    return p;
}
int* func1(){
    // int a =99;
    cout << "AAddr1:" << p << endl;
    cout << "PV1:" << *p << endl;
    return p;
}

int main2(int argc, char *argv[])
{
    p = func();
    cout << "AAddr:" << p << endl;
    cout << "PV:" << *p <<endl;
    func1();
    delete  p ; //
    return 0;
}








int main1() {

    //局部变量
    int a = 10;
    int b = 10;

    //打印地址
    cout << "局部变量a地址为： " <<  &a << endl;
    cout << "局部变量b地址为： " <<  &b << endl;

    cout << "全局变量g_a地址为： " <<   &g_a << endl;
    cout << "全局变量g_b地址为： " <<   &g_b << endl;

    //静态变量
    static int s_a = 10;
    static int s_b = 10;

    cout << "静态变量s_a地址为： " <<  &s_a << endl;
    cout << "静态变量s_b地址为： " <<  &s_b << endl;

    cout << "字符串常量地址为： " <<  &"hello world" << endl;
    cout << "字符串常量地址为： " <<  &"hello world1" << endl;

    cout << "全局常量c_g_a地址为： " <<  &c_g_a << endl;
    cout << "全局常量c_g_b地址为： " <<  &c_g_b << endl;

    const int c_l_a = 10;
    const int c_l_b = 10;
    cout << "局部常量c_l_a地址为： " <<  &c_l_a << endl;
    cout << "局部常量c_l_b地址为： " <<  &c_l_b << endl;

    system("pause");

    return 0;
}

// const int MAX =10;
// int g_a =1;
// const int  g_a_c =2;

// void fun(){
//     static  int i =10; // 并没有改变变量的作用域，保存在全局区
//     i++;
//     cout << "I = " << i <<endl;
// }


// int main(int argc, char *argv[])
// {
//     QCoreApplication a(argc, argv);

//     fun();
//     fun();
//     fun();
//     fun();
//     fun();
//     fun();

//     cout << i;
//     string s ="SUT";
//     cout << "OK" <<endl;
//     return a.exec();
// }
